package com.neudeu.tools;

public class StringTestDriver {
    public static void main(String[]args){
        //test01();
        test02();

    }
    /**
     * 字符串的存储
     */
    private static void test02(){
        //int i=10;   //10就是常量
        //定义一个字符串
        String str00="小明";//此处创建了1个对象
        String str01="小明";//此处创建了1个对象（常量池中的元素不重复）
        //如果只有下面一行代码执行的话，在该行代码之后创建了 2 个对象
        String str10=new String("小明");//创建2个对象：
        String str11=new String("小明");//创建了3个对象

        System.out.println("str00==str10:"+(str00==str10));
        System.out.println("str00==str01:"+(str00==str01));
        System.out.println("str10==str11:"+(str10==str11));
        System.out.println("str00==str11:"+(str00==str11));



    }

    /**
     * String类常用方法：indexOf
     */
    private static void test01(){

        String str0="jbfjbak,fjkdfinfk2fsef,sfe5556482";



        System.out.println("原字符串："+str0);
        System.out.println("f的位置："+str0.indexOf('f'));

        System.out.println("substring截取字符串：");
        System.out.println(""+str0.substring(1));
        System.out.println(""+str0.substring(str0.indexOf('b')));
        System.out.println(""+str0.substring(1,3));
        //System.out.println(""+str0.substring(-1,3));


        System.out.println("字符串分割：");
        String[]strs1=str0.split(",");
        for (String str:strs1) {
            System.out.println(str);
        }

        System.out.println("字符串分割2：");
        String[]strs2=str0.split("[|]");
        for (int i = 0; i <strs2.length ; i++) {
            System.out.println(strs2[i]);
        }

        System.out.println(""+str0.charAt(2));
        System.out.println(str0.codePointAt(5));//codePointAt：返回5位置a的ASCII码
        System.out.println(str0.codePointBefore(1));
        System.out.println(str0.codePointCount(2,4));

        String str1="ab";
        String str2="c";

        System.out.println("aaa:"+str1.compareTo(str2));

        //indexOf
        System.out.println("查找指定下标的字符："+str0.indexOf(97,'b'));


        String newstr0=str0.replace("bak","***");
        System.out.println("Old::"+str0);
        System.out.println("New::"+newstr0);



    }
}
